@extends('layouts.appbook')

@section('content')
    <h1 class="mb-4">书签列表</h1>
    @if (session('success'))
        <div class="alert alert-success">
            {{ session('success') }}
        </div>
    @endif
    <a href="{{ route('bookmarks.create') }}" class="btn btn-primary mb-3">添加新书签</a>
    <table class="table table-striped table-bordered">
        <thead class="table-dark">
            <tr>
                <th>标题</th>
                <th>URL</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            @forelse ($bookmarks as $bookmark)
                <tr>
                    <td>{{ $bookmark->title }}</td>
                    <td><a href="{{ $bookmark->url }}" target="_blank">{{ $bookmark->url }}</a></td>
                    <td>
                        <a href="{{ route('bookmarks.edit', $bookmark->id) }}" class="btn btn-sm btn-warning">编辑</a>
                        <form action="{{ route('bookmarks.destroy', $bookmark->id) }}" method="POST" style="display:inline;">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="btn btn-sm btn-danger" onclick="return confirm('确定删除？')">删除</button>
                        </form>
                    </td>
                </tr>
            @empty
                <tr>
                    <td colspan="3" class="text-center">暂无书签</td>
                </tr>
            @endforelse
        </tbody>
    </table>
@endsection